<?php
    include_once("../action/checkAuthenticationAction.php");
    include_once("../service/productService.php");
    include_once("../service/categoryService.php");
    include_once("../util/constant.php");
    include_once("../util/message.php");
	include_once("../util/functionUtil.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Chi tiết khuyến mãi</title>
	<?php 
        include("import-css.php");
        include("import-css-upload.php");
    ?>
</head>
<body>
    <?php include("header.php");?>
    
	<div class="container-fluid">
		<div class="row-fluid">
            <?php include_once("menu.php");?>
			<div id="content" class="span10">
            	<?php
                    $class = null;
                    $message = null;
                    
                    if(isset($_GET["action"])){
                        $action = $_GET["action"];
                        
                        if($action == UPDATE_SUCCESSFULLY){
                            $message = $messages["changedAdminPassSuccessfully"];
                            $class = FAILED_MESSAGE_CLASS;
                        } else if($action == INSERT_FAILED){
                            $message = $messages["changedAdminPassFailed"];
                            $class = FAILED_MESSAGE_CLASS;
                        }
						
						if(isset($class)){
				?>
                			<div id="msg" class="center alert <?php showClass($class);?>"><?php showMessage($message);?></div>
                <?php
						}
                    }
                ?>
                
            	<div class="box">
                	<div class="box-content">
                    	<form id="fileupload" method="post" enctype="multipart/form-data" class="form-horizontal">
                            <div class="control-group">
                                <label for="categoryTitle" class="control-label">Password cũ</label>
                                <div class="controls">
                                    <input type="password" name="currentPassword" class="input-xlarge focused" value=""/>
                                </div>    
                            </div>
                            <div class="control-group">
                                <label for="categoryTitle" class="control-label">Password mới</label>
                                <div class="controls">
                                    <div class="input-append">
                                        <input type="password" name="newPassword" class="input-xlarge focused" value=""/>
                                    </div>
                                </div>    
                            </div>
                            <div class="control-group">
                                <label for="categoryTitle" class="control-label">Xác nhận password mới</label>
                                <div class="controls">
                                    <div class="input-append">
                                        <input type="password" name="confirmNewPassword" class="input-xlarge focused" value=""/>
                                    </div>
                                </div>    
                            </div>
                            <table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
                            <div class="form-actions">
                            	<button type="button" class="btn btn-primary" onclick="submitForm('fileupload', '../action/changeAdminPass.php', 'post');">Chỉnh sửa</button>
                            </div>
                        </form>
                    </div><!--end of box content-->
                </div><!--end of box-->
            </div><!--end of content-->
        </div><!--end of row fluid-->
        <?php include("footer.php");?>
    </div><!--end of container fluid-->
    <?php include("import-js.php");?>
    
    <script>
        
        $(document).ready(function() {    
            isValidPass = false;
			$.validator.addMethod("validateConfirmPass", function(value) {
				return ($("input[name^=newPassword]").val() == $("input[name^=confirmNewPassword]").val());
			}, "<?php echo $messages["validation.notMatchPassword"]; ?>");
            
            $.validator.addMethod("checkPassword", function(value, element) {
				$.ajax({
					type: "POST",
					url: "../action/ajax/checkAdminPasswordProcess.php",
					data: {"pass" : $("input[name^=currentPassword]").val()},
					success: function(data){
						if(data == 1) {
							isValidPass = true;
						}
						else {  
							isValidPass = false;
						}   
					}
				});
				return isValidPass;
			
			}, "<?php echo $messages["validation.wrongPassword"];?>");
            
            $("#fileupload").validate({
				rules: {
					currentPassword: { checkPassword: true },
					newPassword: { required: true },
					confirmNewPassword: { validateConfirmPass: true },
				},
				//onfocusout: false,
				//onkeyup: false,
				messages: {
					newPassword: "<?php echo $messages["validation.required"];?>"
				}
			});
		});
    </script>
</body>
</html>